package es.us.isa.jdbl.data;

import java.util.LinkedList;
import java.util.List;

import javax.persistence.EntityManager;

import es.us.isa.jdbl.domain.Member;
import es.us.isa.jdbl.domain.biblio.Article;
import es.us.isa.jdbl.domain.biblio.Book;
import es.us.isa.jdbl.domain.biblio.Contributors;

public class BookDAO {

	public static List<Book> getAll(EntityManager em ){
		return em.createQuery("from Book").getResultList();
		
	}
	
	public static List<Book> getByAuthor(EntityManager em, Member m){
	
	
	List<Book> lista = em.createQuery("from Book").getResultList();
	List<Book> resultado = new LinkedList<Book>();
	
	for (Book aux:lista){
		for (Contributors c:aux.getAuthors()){
			if(c.getMemberProfile() != null){
				
				if(c.getMemberProfile().equals(m)){
					resultado.add(aux);
				}
			}
		}
	}
	return resultado;
	}
}
